<!doctype html>
<meta charset=UTF-8 />
<title>App Chat</title>
<script>
function $(id){return document.getElementById(id)};
if (location.protocol=="https") {
  location.replace(location.href.replace(/^http/i,"http"));
} //argh you XDR! and Google OAuth2...
function jsonp(url,onerror) {
  var s = document.createElement("script");
  s.async=true;
  s.src=url;
  s.onerror=onerror;
  document.head.appendChild(s);
}
function oAuthReq() {
  var oauth_url="https://accounts.google.com/o/oauth2/auth",
    params = {
      response_type: "token",
      redirect_uri: "http://gengkev.googlecode.com/svn/trunk/appchat/web/callback.html",
      client_id: "578737917000.apps.googleusercontent.com",
      scope: "https://docs.google.com/feeds/ https://spreadsheets.google.com/feeds/"
    };
  for (var i in params) {
    if (!params.hasOwnProperty(i)) continue;

    oauth_url += (oauth_url.indexOf("?")==-1)?"?":"&";
    oauth_url += i + "=" + params[i];
  }

  location.replace(oauth_url);
}
function load() {
  window.access_token=localStorage.access_token;

  // let us see if we have access to the doc
  var url = "https://docs.google.com/feeds/default/private/full/~/folder?"; //title=App+Chat&title-exact=true";
  var query_params = "v=3&alt=json-in-script&callback=docRequest&access_token="+access_token;
  jsonp(url+query_params);
}
function docRequest(response) {
}
/*
function checkUserEmail(response) {
  try {
    var name = response.entry.author[0].name.$t,
      email = response.entry.author[0].email.$t;
  } catch(e) {
    $("status").innerHTML="Error: something went wrong!";
  }

  if (!(/^.+@fcpsschools\.net$/i).test(email)) {
    $("status").innerHTML="Error: not a <a href=\"http://fcpsschools.net\" target=\"_blank\">fcpsschools.net</a> address! Click that to sign in.)";
  }
  else {
    localStorage["name"]=name;
    localStorage["email"]=email;
    localStorage["access_token"]=access_token;
    // location.replace("index.html");
    $("status").innerHTML="Done! return home.";
  }
}
*/
window.addEventListener("load",load,false);
</script>
<button onclick="oAuthReq()">Login with your fcpsschools.net account<br /><br /><img src="logo.png" alt="FCPS Google Apps" ></button>
<div>Username: <span id="name"></span><br />
Email: <span id="email"></span><br />
Access token: <span id="access_token"></span><br />
</div>